//
//  ShopViewController.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/23.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "ShopViewController.h"
#import "AppDelegate.h"
#import "MainTabBarController.h"
#import "ShopHeaderView.h"
#import "ShopChangeHeaderView.h"
#import "ShopTableViewCell.h"
#import "ShopOrderModel.h"
#import "ScanViewController.h"
#import "SearchViewController.h"
#import "AppDelegate.h"
#import <JMessage/JMessage.h>
#import "ChatRoomViewController.h"
#import "OrderDetailsViewController.h"
#import <CoreLocation/CoreLocation.h>
//#import "JMHttpRequestMethod.h"

@interface ShopViewController ()<UITableViewDelegate,UITableViewDataSource,ShopHeaderViewDelegate,ShopChangeHeaderViewDelegate,CLLocationManagerDelegate>

@property (nonatomic, weak)UIView * navView;
@property (nonatomic, weak)UIImageView * navImageView;
@property (nonatomic, weak)UIImageView * titleView;
@property (nonatomic, strong)UIButton * backButton;
@property (nonatomic, strong)UIButton * searchButton;
@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSArray<ShopOrderModel *> * orderArray;
//@property(strong,nonatomic)UIWindow *window;
//@property(strong,nonatomic)UIButton *button;
//@property (nonatomic, weak)UIToolbar *toolbar;
//@property (nonatomic, weak)UIView * helpView;
@property (nonatomic, weak)UILabel * showLabel;
@property (nonatomic, copy)NSString * type;
@property (nonatomic, assign)int count;
@property (nonatomic, strong) CLLocationManager *locationManager;

@end

@implementation ShopViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self loadDataWithStatus:self.type];
//    [self test];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ZRWhiteColor;
    self.type = @"10";
    self.count = 1;
    
    self.orderArray = [NSArray bg_arrayWithName:@"shopOrder"];
    [self setupNav];
    [self setupUI];
    [self startLocation];
//    [self createButton];
}


- (void)loadDataWithStatus:(NSString *)status{
    
    NSString * shopID = DEF_GET_OBJECT(@"shopid");

    [[ZRNetworkTool sharedTool] getGoodsOrderListResultWithShopID:shopID WithStatus:status WithBlock:^(BOOL success, id responseData) {

        if (success) {
            
            self.orderArray = [NSArray yy_modelArrayWithClass:[ShopOrderModel class] json:responseData[@"data"]];
            
            if (self.count == 1) {

                NSArray* testResult = [NSArray bg_arrayWithName:@"shopOrder"];
                if (testResult.count > 0) {
                    
                    [NSArray bg_clearArrayWithName:@"shopOrder"];
                    [self.orderArray bg_saveArrayWithName:@"shopOrder"];
                }else{
                    
                    [self.orderArray bg_saveArrayWithName:@"shopOrder"];
                }
            }
            
            self.count = self.count + 1;
        }
    }];
}


- (void)setOrderArray:(NSArray<ShopOrderModel *> *)orderArray{
    
    _orderArray = orderArray;
    
    [self.tableView reloadData];
}

- (void)setupNav{
    
    UIView * navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kStatusBarHeight + kNavHeight)];
    
    navView.backgroundColor = ColorWithRGB(0xFFE055);
    navView.userInteractionEnabled = YES;
    
    self.navView = navView;
    
    [self.view addSubview:self.navView];
    
    UIImageView * navImageView = [UIImageView new];

    navImageView.image = [UIImage imageNamed:@"Group6"];
    
    self.navImageView = navImageView;
    
    [self.navView addSubview:self.navImageView];
    
    self.searchButton = [self setupButtonWithImage:@"search(2)"];
    [self.navView addSubview:self.searchButton];
    self.backButton = [self setupButtonWithImage:@"logout(1)"];
    [self.navView addSubview:self.backButton];
    
    UIImageView * titleView = [UIImageView new];
    
    titleView.image = [UIImage imageNamed:@"logo"];
    
    self.titleView = titleView;
    
    [self.navView addSubview:self.titleView];
    
    
    NSString * user_id = DEF_GET_OBJECT(@"id");

    [[ZRNetworkTool sharedTool] getUserInfoResultWithUser_id:user_id WithExamine_user_id:@"" WithBlock:^(BOOL success, id responseData) {

        if (success) {

//            NSLog(@"res===%@",responseData);

            NSDictionary * dict = responseData[@"data"];
            NSString * phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
            NSString * user_name = [NSString stringWithFormat:@"%@",dict[@"user_name"]];
            int jiguang_register_status = [dict[@"jiguang_register_status"] intValue];

            NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,dict[@"head_img"]];
            DEF_SET_OBJECT(imgStr, @"imgStr");
            DEF_SET_OBJECT(phone, @"phone");
            DEF_SET_OBJECT(user_name, @"name");

            NSURL * url = [NSURL URLWithString:imgStr];
            //            UIImage * imaa = [UIImage ];
            NSData *data = [NSData dataWithContentsOfURL:url];

            [JMSGUser updateMyInfoWithParameter:user_name userFieldType:kJMSGUserFieldsNickname completionHandler:^(id resultObject, NSError *error) {

                if (error == nil) {

//                    NSLog(@"===更改成功");
                } else {

                }
            }];

            [JMSGUser updateMyInfoWithParameter:data userFieldType:kJMSGUserFieldsAvatar completionHandler:^(id resultObject, NSError *error) {

                if (error == nil) {
//                                        NSLog(@"===shanghcuan");
                    //                    [MBProgressHUD showMessage:@"上传成功" view:self.view];
                } else {
//                                        NSLog(@"===shibai");
                    //                    [MBProgressHUD showMessage:@"上传失败!" view:self.view];
                }
            }];


            if (jiguang_register_status == 1) {

                [JMSGUser loginWithUsername:phone password:phone completionHandler:^(id resultObject, NSError *error) {

                    if (error == nil) {
                        
                    }else{

//                        NSLog(@"error===%@",error);
                    }
                }];
            }else{

                JMSGUserInfo *info = [[JMSGUserInfo alloc]init];
                info.nickname = user_name;

                [JMSGUser registerWithUsername:phone password:phone userInfo:info completionHandler:^(id resultObject, NSError *error) {
                    if (!error) {
                        //注册成功
                        [[ZRNetworkTool sharedTool] updateUserInfoWithUpdate_Class:@"jiguang_register_status" WithUpdate_content:@"1" WithBlock:^(BOOL success, id responseData) {

                            if (success) {

                                NSLog(@"===注册成功");
                            }
                        }];
                    } else {
                        //注册失败
//                        NSLog(@"===注册失败");
                    }
                }];
            }
        }
    }];
    
//    if (DEF_GET_OBJECT(@"lat") && DEF_GET_OBJECT(@"lon")) {
//        
//        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
//        //现在时间,你可以输出来看下是什么格式
//        NSDate *datenow = [NSDate date];
//        //----------将nsdate按formatter格式转成nsstring
//        NSString *currentTimeString = [formatter stringFromDate:datenow];
//        
//        NSLog(@"currentTimeString==%@",currentTimeString);
//        NSString * lat = DEF_GET_OBJECT(@"lat");
//        NSString * lon = DEF_GET_OBJECT(@"lon");
//        
//        NSDictionary * dict = @{@"address_longitude":lon,@"address_latitude":lat,@"lost_login_time":currentTimeString};
//
//        
//        [[ZRNetworkTool sharedTool] updateUserInfoAllWithDict:dict WithBlock:^(BOOL success, id responseData) {
//           
//        }];
//    }
}


- (void)setupUI{
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusBarHeight + kNavHeight, kScreenW, kScreenH - kTabBarHeight - kStatusBarHeight - kNavHeight) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = ColorWithRGB(0xF8F9FA);
    tableView.rowHeight = 165 * SCREENH6;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.showsVerticalScrollIndicator = NO;
    
    ShopHeaderView * headerView =  [[ShopHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 115 * SCREENH6)];
    // 设置header
    tableView.tableHeaderView = headerView;
    headerView.shopHeaderViewDelegate = self;
    //    self.tableView.bounces = NO;
    //    self.tableView.estimatedRowHeight = 150 * SCREENH6;//估算高度
    //    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    self.tableView = tableView;
    
    [self.tableView registerClass:[ShopTableViewCell class] forCellReuseIdentifier:@"ShopListCell"];
    [self.tableView registerClass:[ShopChangeHeaderView class] forHeaderFooterViewReuseIdentifier:@"ShopChangeHeaderView"];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self updateData];
    }];
    
    [self.view addSubview:self.tableView];
    
    
    UILabel * showLabel = [UILabel new];
    
    showLabel.textColor = ZRBlackColor;
    showLabel.text = @"暂无订单";
    showLabel.font = [UIFont systemFontOfSize:18 * SCREENH6];
    showLabel.textAlignment = NSTextAlignmentCenter;
    showLabel.hidden = YES;
    
    self.showLabel = showLabel;
    
    [self.view addSubview:self.showLabel];
}


- (void)viewDidLayoutSubviews{
    
    [self.navImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.navView);
        make.height.mas_equalTo(30 * SCREENH6);
    }];
    
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.navView).offset(kStatusBarHeight + 10 * SCREENH6);
    }];
    
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.titleView);
    }];
    
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.backButton);
    }];
    
    [self.showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.centerY.mas_equalTo(self.view).offset(50 * SCREENH6);
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (self.orderArray.count == 0) {
        
        self.showLabel.hidden = NO;
    }else{
        
        self.showLabel.hidden = YES;
    }
    return self.orderArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ShopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopListCell" forIndexPath:indexPath];
    
    cell.model = self.orderArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 40 * SCREENH6;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    ShopChangeHeaderView * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"ShopChangeHeaderView"];
    header.shopChangeHeaderViewDelegate = self;
    
    return header;
}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    if ([view isKindOfClass:[UITableViewHeaderFooterView class]]) {
        ((UITableViewHeaderFooterView *)view).backgroundView.backgroundColor = ColorWithRGB(0xF8F9FA);
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HiddenBar;
    
    ShopOrderModel * model = self.orderArray[indexPath.row];
    
    OrderDetailsViewController * orderVC = [OrderDetailsViewController new];
    
    orderVC.ID = model.id;
    orderVC.from = @"shop";
    //    orderVC.disLabel.hidden = YES;
    
    [self.navigationController pushViewController:orderVC animated:YES];
    
    
    ShowBar;
}


- (void)clickItemButton:(NSString *)type{
    
    self.type = type;
    self.orderArray = nil;
    [self loadDataWithStatus:type];
}


- (UIButton *)setupButtonWithImage:(NSString *)image{
    
    UIButton * button = [UIButton new];
    
    [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickNavButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    return button;
}


- (void)clickNavButton:(UIButton *)button{
    
    if (button == self.backButton) {
        
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        MainTabBarController *tabs = [[MainTabBarController alloc] init];
        tabs.selectedIndex = 3;
        tabs.delegate = appDelegate;
        appDelegate.window.rootViewController = tabs;
    }else if (button == self.searchButton){
        
        HiddenBar;
        SearchViewController * searchVC = [SearchViewController new];

        [self.navigationController pushViewController:searchVC animated:YES];

        ShowBar;
    }
}

- (void)clickItemButton{
    
    HiddenBar;
    
    ScanViewController * scanVC = [ScanViewController new];
    
    [self.navigationController pushViewController:scanVC animated:YES];
    ShowBar;
}

#pragma mark - TableView 占位图
- (NSString *)xy_noDataViewMessage {
    
    return @"";
}

- (UIColor *)xy_noDataViewMessageColor {
    
    return [UIColor blackColor];
}

//-(void)createButton{
//    if (!_button) {
//        _window = [[UIApplication sharedApplication] keyWindow];
//        _window.backgroundColor = [UIColor whiteColor];
//        [_window addSubview:self.button];
//        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:
//                                       self action:@selector(locationChange:)];
//        pan.delaysTouchesBegan = YES;
//        [_button addGestureRecognizer:pan];
//    }
//}
//
//-(UIButton*)button{
//    if (!_button) {
//        _button = [UIButton buttonWithType:UIButtonTypeCustom];
//        //        _button.backgroundColor = [UIColor redColor];
//        [_button setImage:[UIImage imageNamed:@"全局浮动按钮"] forState:UIControlStateNormal];
//        _button.frame = CGRectMake(kScreenW - 65 * SCREENH6, 300 * SCREENH6, 65 * SCREENH6, 65 * SCREENH6);//初始在屏幕上的位置
//        //_button.layer.cornerRadius = 33;
//        //_button.layer.masksToBounds = YES;
//        [_button addTarget:self action:@selector(clickSeverceButton) forControlEvents:UIControlEventTouchUpInside];
//    }
//    return _button;
//}
//
//-(void)locationChange:(UIPanGestureRecognizer*)p{
//    CGFloat HEIGHT=_button.frame.size.height;
//    CGFloat WIDTH=_button.frame.size.width;
//    CGPoint panPoint = [p locationInView:[UIApplication sharedApplication].windows[0]];
//    if(p.state == UIGestureRecognizerStateChanged){
//        _button.center = CGPointMake(panPoint.x, panPoint.y);
//    }
//    else if(p.state == UIGestureRecognizerStateEnded){
//        if(panPoint.x <= kScreenW/2) {
//            if(panPoint.y <= 40+HEIGHT/2 && panPoint.x >= 20+WIDTH/2)  {
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(panPoint.x, HEIGHT/2);
//                }];
//            } else if(panPoint.y >= kScreenH-HEIGHT/2-40 && panPoint.x >= 20+WIDTH/2){
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(panPoint.x, kScreenH-HEIGHT/2);
//                }];
//            }  else if (panPoint.x < WIDTH/2+15 && panPoint.y > kScreenH-HEIGHT/2){
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(WIDTH/2, kScreenH-HEIGHT/2);
//                }];
//            }  else{
//                CGFloat pointy = panPoint.y < HEIGHT/2 ? HEIGHT/2 :panPoint.y;
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(WIDTH/2, pointy);
//                }];
//            }
//        } else if(panPoint.x > kScreenW/2)
//        {
//            if(panPoint.y <= 40+HEIGHT/2 && panPoint.x < kScreenW-WIDTH/2-20 ) {
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(panPoint.x, HEIGHT/2);
//                }];
//            }else if(panPoint.y >= kScreenH-40-HEIGHT/2 && panPoint.x < kScreenW-WIDTH/2-20) {
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(panPoint.x, kScreenH-HEIGHT/2);
//                }];
//            }else if (panPoint.x > kScreenW-WIDTH/2-15 && panPoint.y < HEIGHT/2) {
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(kScreenW-WIDTH/2, HEIGHT/2);
//                }];
//            } else{
//                CGFloat pointy = panPoint.y > kScreenH-HEIGHT/2 ? kScreenH-HEIGHT/2 :panPoint.y;
//                [UIView animateWithDuration:0.2 animations:^{
//                    self->_button.center = CGPointMake(kScreenW-WIDTH/2, pointy);
//                }];
//            }
//        }
//    }
//}
//
//
//- (void)clickSeverceButton{
//
//    UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:[UIScreen mainScreen].bounds];
//    //样式
//    toolbar.barStyle = UIBarStyleBlackTranslucent;//半透明
//    //透明度
//    toolbar.alpha = 0.5f;
//    toolbar.userInteractionEnabled = YES;
//
//    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
//    [toolbar addGestureRecognizer:tapGR];
//
//    //    self.toolbar = toolbar;
//    [self.tabBarController.view addSubview:toolbar];
//
//    UIView * helpView = [[UIView alloc] initWithFrame:CGRectMake(62.5 * SCREENH6, kScreenH/2 - 120 * SCREENH6, 250 * SCREENH6, 203 * SCREENH6)];
//
//    helpView.backgroundColor = ZRWhiteColor;
//    helpView.userInteractionEnabled = YES;
//    helpView.layer.cornerRadius = 5 * SCREENH6;
//    helpView.layer.masksToBounds = YES;
//
//    //    self.helpView = helpView;
//
//    [self.tabBarController.view addSubview:helpView];
//
//    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 8 * SCREENH6, 250 * SCREENH6, 30 * SCREENH6)];
//
//    titleLabel.text = @"联系客服";
//    titleLabel.textColor = [UIColor lightGrayColor];
//    titleLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
//    titleLabel.textAlignment = NSTextAlignmentCenter;
//
//    [helpView addSubview:titleLabel];
//
//    UIView * oneLineView = [self setupLineView];
//    oneLineView.frame = CGRectMake(10 * SCREENH6, 45 * SCREENH6, 230 * SCREENH6, 1 * SCREENH6);
//    [helpView addSubview:oneLineView];
//    UIView * twoLineView = [self setupLineView];
//    twoLineView.frame = CGRectMake(10 * SCREENH6, 75 * SCREENH6, 230 * SCREENH6, 1 * SCREENH6);
//    [helpView addSubview:twoLineView];
//    UIView * threeLineView = [self setupLineView];
//    threeLineView.frame = CGRectMake(10 * SCREENH6, 95 * SCREENH6, 230 * SCREENH6, 1 * SCREENH6);
//    [helpView addSubview:threeLineView];
//    UIView * fourLineView = [self setupLineView];
//    fourLineView.frame = CGRectMake(10 * SCREENH6, 125 * SCREENH6, 230 * SCREENH6, 1 * SCREENH6);
//    [helpView addSubview:fourLineView];
//
//    UIButton * msgButton = [[UIButton alloc] initWithFrame:CGRectMake(10 * SCREENH6, 46 * SCREENH6, 230 * SCREENH6, 30 * SCREENH6)];
//
//    msgButton.tag = 2001;
//    [msgButton setTitle:@"在线客服" forState:UIControlStateNormal];
//    [msgButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
//    [msgButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];
//    msgButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
//
//    [helpView addSubview:msgButton];
//
//    UIButton * telButton = [[UIButton alloc] initWithFrame:CGRectMake(10 * SCREENH6, 96 * SCREENH6, 230 * SCREENH6, 30 * SCREENH6)];
//
//    telButton.tag = 2002;
//    [telButton setTitle:@"客服电话" forState:UIControlStateNormal];
//    [telButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
//    [telButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];
//    telButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
//
//    [helpView addSubview:telButton];
//
//
//    UIButton * closeButton = [[UIButton alloc] initWithFrame:CGRectMake(50 * SCREENH6, 146 * SCREENH6, 150 * SCREENH6, 30 * SCREENH6)];
//
//    closeButton.tag = 2003;
//    [closeButton setTitle:@"关闭" forState:UIControlStateNormal];
//    [closeButton setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
//    [closeButton setBackgroundColor:ColorWithRGB(0xff5c5c)];
//    [closeButton addTarget:self action:@selector(clickCallOrMsgToSeverice:) forControlEvents:UIControlEventTouchUpInside];
//    closeButton.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
//    closeButton.layer.cornerRadius = 5 * SCREENH6;
//    closeButton.layer.masksToBounds = YES;
//
//    [helpView addSubview:closeButton];
//
//    //    [helpView mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.centerX.mas_equalTo(self.view);
//    //        make.centerY.mas_equalTo(self.view).offset(20 * SCREENH6);
//    //        make.width.mas_equalTo(250 * SCREENH6);
//    //        make.height.mas_equalTo(203 * SCREENH6);
//    //    }];
//    //
//    //    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.centerX.mas_equalTo(helpView);
//    //        make.top.mas_equalTo(helpView).offset(15 * SCREENH6);
//    //    }];
//    //
//    //    [oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.mas_equalTo(helpView).offset(15 * SCREENH6);
//    //        make.trailing.mas_equalTo(helpView).offset(-15 * SCREENH6);
//    //        make.top.mas_equalTo(titleLabel.mas_bottom).offset(15 * SCREENH6);
//    //        make.height.mas_equalTo(1 * SCREENH6);
//    //    }];
//    //
//    //    [msgButton mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.trailing.mas_equalTo(oneLineView);
//    //        make.top.mas_equalTo(oneLineView.mas_bottom);
//    //        make.height.mas_equalTo(30 * SCREENH6);
//    //    }];
//    //
//    //    [twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.trailing.height.mas_equalTo(oneLineView);
//    //        make.top.mas_equalTo(msgButton.mas_bottom);
//    //    }];
//    //
//    //    [threeLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.trailing.height.mas_equalTo(twoLineView);
//    //        make.top.mas_equalTo(twoLineView.mas_bottom).offset(20 * SCREENH6);
//    //    }];
//    //
//    //    [telButton mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.trailing.height.mas_equalTo(msgButton);
//    //        make.top.mas_equalTo(threeLineView.mas_bottom);
//    //    }];
//    //
//    //    [fourLineView mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.leading.trailing.height.mas_equalTo(threeLineView);
//    //        make.top.mas_equalTo(telButton.mas_bottom);
//    //    }];
//    //
//    //    [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
//    //        make.centerX.mas_equalTo(helpView);
//    //        make.top.mas_equalTo(fourLineView.mas_bottom).offset(20 * SCREENH6);
//    //        make.width.mas_equalTo(150 * SCREENH6);
//    //        make.height.mas_equalTo(30 * SCREENH6);
//    //    }];
//}
//
//
//- (void)tapAction{
//
//    //    [self.toolbar removeFromSuperview];
//    //    [self.helpView removeFromSuperview];
//    for (UIView *subView in self.tabBarController.view.subviews) {
//
//        if (subView.frame.size.width == 250 * SCREENH6) {
//
//            [subView removeFromSuperview];
//        }
//        if (subView.alpha == 0.5) {
//
//            [subView removeFromSuperview];
//        }
//    }
//
//}
//
//
//
//- (UIView *)setupLineView{
//
//    UIView * lineView = [UIView new];
//
//    lineView.backgroundColor = ColorWithRGB(0xe4e4e4);
//
//    return lineView;
//}
//
//
//- (void)clickCallOrMsgToSeverice:(UIButton *)button{
//
//    if (button.tag == 2001) {
//
//        NSString * merchants_admin_phone = @"17781489591";
//
//        [JMSGConversation createSingleConversationWithUsername:merchants_admin_phone completionHandler:^(id resultObject, NSError *error) {
//
//            if (error == nil) {
//
//                for (UIView *subView in self.tabBarController.view.subviews) {
//
//                    if (subView.frame.size.width == 250 * SCREENH6) {
//
//                        [subView removeFromSuperview];
//                    }
//                    if (subView.alpha == 0.5) {
//
//                        [subView removeFromSuperview];
//                    }
//                }
//
//                HiddenBar;
//                ChatRoomViewController * roomVC = [ChatRoomViewController new];
//
//                roomVC.conversation = resultObject;
//
//                [[self getCurrentVC].navigationController pushViewController:roomVC animated:YES];
//
//                ShowBar;
//
//            } else {
//
//            }
//        }];
//
//    }else if (button.tag == 2002){
//
//        NSString * str = @"tel:028-65279781";
//
//        UIWebView * callWebview = [[UIWebView alloc] init];
//
//        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//
//        [self.view addSubview:callWebview];
//
//        for (UIView *subView in self.tabBarController.view.subviews) {
//
//            if (subView.frame.size.width == 250 * SCREENH6) {
//
//                [subView removeFromSuperview];
//            }
//            if (subView.alpha == 0.5) {
//
//                [subView removeFromSuperview];
//            }
//        }
//
//    }else if (button.tag == 2003){
//
//        for (UIView *subView in self.tabBarController.view.subviews) {
//
//            if (subView.frame.size.width == 250 * SCREENH6) {
//
//                [subView removeFromSuperview];
//            }
//            if (subView.alpha == 0.5) {
//
//                [subView removeFromSuperview];
//            }
//        }
//    }
//}
//
//- (UIViewController *)getCurrentVC {
//    
//    UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
//    if (!window) {
//        return nil;
//    }
//    UIView *tempView;
//    for (UIView *subview in window.subviews) {
//        if ([[subview.classForCoder description] isEqualToString:@"UILayoutContainerView"]) {
//            tempView = subview;
//            break;
//        }
//    }
//    if (!tempView) {
//        tempView = [window.subviews lastObject];
//    }
//    
//    id nextResponder = [tempView nextResponder];
//    while (![nextResponder isKindOfClass:[UIViewController class]] || [nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UITabBarController class]]) {
//        tempView =  [tempView.subviews firstObject];
//        
//        if (!tempView) {
//            return nil;
//        }
//        nextResponder = [tempView nextResponder];
//    }
//    return  (UIViewController *)nextResponder;
//}


- (void)updateData{
    
    [self loadDataWithStatus:self.type];
    [self.tableView.mj_header endRefreshing];
}


//开始定位
- (void)startLocation {
    
    if ([CLLocationManager locationServicesEnabled]) {
        //        CLog(@"--------开始定位");
        self.locationManager = [[CLLocationManager alloc]init];
        self.locationManager.delegate = self;
        //控制定位精度,越高耗电量越
        self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        // 总是授权
        [self.locationManager requestWhenInUseAuthorization];
        self.locationManager.distanceFilter = 10.0f;
        //        [self.locationManager requestAlwaysAuthorization];
        [self.locationManager startUpdatingLocation];
    }
}


- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    if ([error code] == kCLErrorDenied) {
        NSLog(@"访问被拒绝");
    }
    if ([error code] == kCLErrorLocationUnknown) {
        NSLog(@"无法获取位置信息");
    }
}
//定位代理经纬度回调
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    
    CLLocation *newLocation = locations[0];
    
    //    self.userLocation = newLocation;
    
    double lat = newLocation.coordinate.latitude;
    double lon = newLocation.coordinate.longitude;
    
    NSString * latStr = [NSString stringWithFormat:@"%f",lat];
    NSString * lonStr = [NSString stringWithFormat:@"%f",lon];
    
    DEF_SET_OBJECT(latStr, @"lat");
    DEF_SET_OBJECT(lonStr, @"lon");
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    //现在时间,你可以输出来看下是什么格式
    NSDate *datenow = [NSDate date];
    //----------将nsdate按formatter格式转成nsstring
    NSString *currentTimeString = [formatter stringFromDate:datenow];;
    
    NSDictionary * dict = @{@"address_longitude":lonStr,@"address_latitude":latStr,@"lost_login_time":currentTimeString};
    
    
    [[ZRNetworkTool sharedTool] updateUserInfoAllWithDict:dict WithBlock:^(BOOL success, id responseData) {
        
        //        NSLog(@"res==%@",responseData);
    }];
}

@end
